How can we get a sense of where the available scooters are located in Arlington County? This page lists access points for the vendors operating in the County. We can pull in this data in real-time with the caveat that it only includes devices that are not currently in use.

library(gbfs)
library(tidyverse)
library(jsonlite)
library(flexdashboard)
library(sf)
library(lubridate)
library(plotly)

all.cities <- get_gbfs_cities()
us.cities <- subset(all.cities, `Country Code` == "US")


spin_0 <- fromJSON("https://gbfs.spin.pm/api/gbfs/v1/arlington_virginia/free_bike_status")
spin <- spin_0$data$bikes
spin <- spin %>%
  mutate(vendor = "Spin")

lime_0 <- fromJSON("https://mds.bird.co/gbfs/arlingtonco/free_bikes")
lime <- lime_0$data$bikes
lime <- lime %>%
  mutate(vendor = "Lime")

bird_0 <- fromJSON("https://mds.bird.co/gbfs/arlingtonco/free_bikes")
bird <- bird_0$data$bikes
bird <- bird %>%
  mutate(vendor = "Bird")


devices <- bind_rows(spin, lime, bird) 

devices <- devices %>% select(-vehicle_type)


It should be noted that the Skip feed does not work, probably because the company filed for bankruptcy in the fall of 2021.

An invisible code chunk loads a MapBox API key below.


Now let’s create an interactive map that shows the location of available scooters by vendor.


plot_mapbox(devices, lat = ~lat, lon = ~lon, mode = 'scattermapbox')  %>% 
  add_markers(lat = ~lat, lon = ~lon, text  = ~paste(bike_id, "\n", vendor),
              color = ~vendor, colors = c("red", "green", "blue"), size = 3000, hoverinfo = "text") %>%
  layout(
    mapbox = list(zoom = 12, center = list(lat = ~median(devices$lat), 
                                           lon = ~median(devices$lon))),
    title = "Available Spin Scooters in Arlington County", 
    legend = list(orientation = 'h',
                  font = list(size = 8)))